Private Sub mnuFormatLinesSections_Click()
Dim result%, jobnum%, mainjob%, sectionN%, sectionCode%, MinimumHeight%, nDetailCopies%, lineN%, LineHeight%, LineAscent%
Dim TempText$
Dim SectionOptions As PESectionOptions
If Not CRYSTAL_PRO Then
MsgBox "Options are a Crystal Pro only feature.", vbOKOnly + vbCritical, "Crystal Pro Only"
Exit Sub
End If
result% = PEOpenEngine()
If result% = 0 Then
MsgBox "Could not start the report engine. Execution must halt.", vbOKOnly + vbCritical, "Serious Error"
End
End If
jobnum% = PEOpenPrintJob(lblReportName.Caption) ' Name from label on sample form
ErrorTrap "OpenPrintJob in FormatLinesSections", jobnum%
' Subreport check - if a subreport is currently selected on the main form, jobnum% becomes the subreport
If lblSubreportName.Visible Then
mainjob% = jobnum%
jobnum% = PEOpenSubreport(mainjob%, lblSubreportName.Caption)
ErrorTrap "OpenSubReport in FormatLinesSections", mainjob%
End If
' Define the size of the SectionOptions structure
SectionOptions.StructSize = PE_SIZEOF_SECTION_OPTIONS
' Load the Sections form for displaying the selection of sections available
Load Sections
CenterForm Sample, Sections
Sections.Caption = "Edit Sections"
' Fill section list box with appropriate sections for report
result% = PEGetNSections(jobnum%)
ErrorTrap "GetNSections in FormatLinesSections", jobnum%
For sectionN% = 0 To result% - 1
sectionCode% = PEGetSectionCode(jobnum%, sectionN%)
ErrorTrap "GetSectionCode in FormatLinesSections", jobnum%
Select Case sectionCode%
Case Is >= 8000
TempText$ = "Report Footer"
Case Is >= 7000
TempText$ = "Page Footer"
Case Is >= 5000
TempText$ = "Group Footer"
Case Is >= 4000
TempText$ = "Detail"
Case Is >= 3000
TempText$ = "Group Header"
Case Is >= 2000
TempText$ = "Page Header"
Case Is >= 1000
TempText$ = "Report Header"
Case Else
TempText$ = "Unknown Section"
End Select
Sections!lstSections.AddItem TempText$
Sections!lstSections.ItemData(Sections!lstSections.NewIndex) = sectionCode%
Next sectionN%
' Start a loop for setting different section settings - exit by pressing Ok on the sections form
Do While True
' Show Section selector form 1 ' Modally
Sections.Show 1 ' Modal
' Find which button was pressed to hide the Sections form
Select Case Sections.Tag
Case "Ok"
Exit Do
Case "Edit"
' Get the section code from the Section form
sectionCode% = Sections!lstSections.ItemData(Sections!lstSections.ListIndex)
' Load Section edit form
Load SectionEdit
CenterForm Sample, SectionEdit
' Get Section format data
result% = PEGetSectionFormat(jobnum%, sectionCode%, SectionOptions)
ErrorTrap "GetSectionFormat in FormatLinesSections", jobnum%
' Fill in section format data on form
SectionEdit!chkVisible.Value = IIf(SectionOptions.Visible, 1, 0)
SectionEdit!chkNewPageBefore.Value = IIf(SectionOptions.NewPageBefore, 1, 0)
SectionEdit!chkNewPageAfter.Value = IIf(SectionOptions.NewPageAfter, 1, 0)
SectionEdit!chkKeepTogether.Value = IIf(SectionOptions.KeepTogether, 1, 0)
SectionEdit!chkSuppressBlankLines.Value = IIf(SectionOptions.SuppressBlankSection, 1, 0)
SectionEdit!chkResetPageNAfter.Value = IIf(SectionOptions.ResetPageNAfter, 1, 0)
SectionEdit!chkprintAtBottomOfPage.Value = IIf(SectionOptions.PrintAtBottomOfPage, 1, 0)
' Get minimum section height
result% = PEGetMinimumSectionHeight(jobnum%, sectionCode%, MinimumHeight%)
ErrorTrap "GetMinimumSectionHeight in FormatLinesSections", jobnum%
' Fill in minimum section height
SectionEdit!txtMinHeight.Text = MinimumHeight%
' Get number of times each detail section is printed
result% = PEGetNDetailCopies(jobnum%, nDetailCopies%)
ErrorTrap "GetNDetailCopies in FormatLinesSections", jobnum%
' Fill in number of times detail section is printed
SectionEdit!txtNDetailCopies.Text = nDetailCopies%
' Another infinite loop
Do While True
' Display SectionEdit form
SectionEdit.Show 1 ' Modal
Select Case SectionEdit.Tag
Case "Ok"
' Get section format data from form
If SectionEdit!chkVisible.Value = 1 Then SectionOptions.Visible = True Else SectionOptions.Visible = False
If SectionEdit!chkNewPageBefore.Value = 1 Then SectionOptions.NewPageBefore = True Else SectionOptions.NewPageBefore = False
If SectionEdit!chkNewPageAfter.Value = 1 Then SectionOptions.NewPageAfter = True Else SectionOptions.NewPageAfter = False
If SectionEdit!chkKeepTogether.Value = 1 Then SectionOptions.KeepTogether = True Else SectionOptions.KeepTogether = False
If SectionEdit!chkSuppressBlankLines.Value = 1 Then SectionOptions.SuppressBlankSection = True Else SectionOptions.SuppressBlankSection = False
If SectionEdit!chkResetPageNAfter.Value = 1 Then SectionOptions.ResetPageNAfter = True Else SectionOptions.ResetPageNAfter = False
If SectionEdit!chkprintAtBottomOfPage.Value = 1 Then SectionOptions.PrintAtBottomOfPage = True Else SectionOptions.PrintAtBottomOfPage = False
' Set into report
result% = PESetSectionFormat(jobnum%, sectionCode%, SectionOptions)
ErrorTrap "SetSectionFormat in FormatLinesSections", jobnum%
' Get minimum section height from form
MinimumHeight% = Val(SectionEdit!txtMinHeight.Text)
result% = PESetMinimumSectionHeight(jobnum%, sectionCode%, MinimumHeight%)
ErrorTrap "SetMinimumSectionHeight in FormatLinesSections", jobnum%
' If a font name has been entered, change the font of the section
If Len(Trim(SectionEdit!txtFontName.Text)) <> 0 Then
result% = PESetFont(jobnum%, sectionCode%, IIf(SectionEdit!chkFields.Value = 1, PE_FIELDS, 0) Or IIf(SectionEdit!chkText.Value = 1, PE_TEXT, 0), SectionEdit!txtFontName.Text, FF_DONTCARE, DEFAULT_PITCH, ANSI_CHARSET, Val(SectionEdit!txtFontSize.Text), IIf(SectionEdit!chkItalics.Value = 1, True, False), IIf(SectionEdit!chkUnderline.Value = 1, True, False), IIf(SectionEdit!chkStrikethru.Value = 1, True, False), IIf(SectionEdit!chkBold.Value = 1, FW_BOLD, FW_NORMAL))
ErrorTrap "SetFont in FormatLinesSections", jobnum%
End If
' Get number of times each detail section is printed
nDetailCopies% = Val(SectionEdit!txtNDetailCopies.Text)
result% = PESetNDetailCopies(jobnum%, nDetailCopies%)
ErrorTrap "SetNDetailCopies in FormatLinesSections", jobnum%
Exit Do
Case "Cancel"
MsgBox "Cancel was pressed - no changes will be made to the section settings", vbOKOnly + vbCritical, "Cancel Pressed"
Exit Do
End Select
Loop
Unload SectionEdit
End Select
Loop
Unload Sections
' Offer opportunity to see what you did to the report
If MsgBox("Do you want to preview the report?", vbYesNo + vbQuestion, "Preview Report?") = vbYes Then
' Simplified version of the custom-l ink preview routine (no custom buttons)
result% = PEOutputToWindow(jobnum%, "Lines/Section Demonstration Preview" & Chr$(0), CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0)
ErrorTrap "OutputtoWindow in FormatLinesSections", jobnum%
result% = PEStartPrintJob(jobnum%, True)
ErrorTrap "StartPrintJob in FormatLinesSections", jobnum%
result% = 1
Do While result% <> 0
DoEvents
DoEvents
result% = PEGetWindowHandle(jobnum%)
Loop
End If
' Close print job and engine
' Subreport check - if a subreport is currently open, call PreviewReport to offer a chance to
' preview the main report, then close the subreport and main report
If lblSubreportName.Visible Then
PreviewReport mainjob%
result% = PECloseSubreport(jobnum%)
ErrorTrap "CloseSubReport in FormatLinesSections", mainjob%
PEClosePrintJob mainjob%
Else
PEClosePrintJob jobnum%
End If
PECloseEngine
MsgBox "Lines/Sections Complete!", vbOKOnly, "Operation Succeeded"
End Sub
ActiveX
Private Sub mnuFormatLinesSections_Click()
Dim sectionFormatN As Integer, sectionMinHeightN As Integer
Dim sectionLineHeightN As Integer, sectionFontN As Integer
Dim TempText As String
Dim hwndPreviewWindow As Long
If Not CRYSTAL_PRO Then
MsgBox "Options are a Crystal Pro only feature.", vbOKOnly + vbCritical, "Crystal Pro Only"
Exit Sub
End If
CrystalReport1.ReportFileName = lblReportName.Caption ' Name from label on sample form
' Load the Sections form for displaying the selection of sections available
Load Sections
CenterForm Sample, Sections
Sections.Caption = "Edit Sections"
' Start a loop for setting different section settings - exit by pressing Ok on the sections form
Do While True
' Show Section selector form modally
Sections.Show 1
' Find which button was pressed to hide the Sections form
Select Case Sections.Tag
Case "Ok"
Exit Do
Case "Edit"
' Load Section edit form
Load SectionEdit
CenterForm Sample, SectionEdit
' Another infinite loop
Do While True
' Display SectionEdit form
SectionEdit.Show 1
Select Case SectionEdit.Tag
Case "Ok"
' Do section format
' Build section name
TempText = Sections!cmbSectionType.Text & "." & Sections!txtGroup.Text & "." & Sections!txtSectionNumber.Text
' Get section format data from form
If SectionEdit!chkVisible.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
If SectionEdit!chkNewPageBefore.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
If SectionEdit!chkNewPageAfter.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
If SectionEdit!chkKeepTogether.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
If SectionEdit!chkSuppressBlankLines.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
If SectionEdit!chkResetPageNAfter.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
If SectionEdit!chkprintAtBottomOfPage.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
' Load into report and increment counter
CrystalReport1.SectionFormat(sectionFormatN) = TempText
sectionFormatN = sectionFormatN + 1
' Get minimum section height from form
If Val(SectionEdit!txtMinHeight.Text) <> 0 Then
TempText = Sections!cmbSectionType.Text & "." & Sections!txtGroup.Text & "." & Sections!txtSectionNumber.Text
TempText = TempText & ";" & SectionEdit!txtMinHeight.Text
CrystalReport1.SectionMinHeight(sectionMinHeightN) = TempText
sectionMinHeightN = sectionMinHeightN + 1
End If
' Get line changes for section from form
If Val(SectionEdit!txtLineNum.Text) <> 0 Then
TempText = Sections!cmbSectionType.Text & "." & Sections!txtGroup.Text & "." & Sections!txtSectionNumber.Text
TempText = TempText & ";" & SectionEdit!txtLineNum.Text & ";" & SectionEdit!txtHeight.Text & ";" & SectionEdit!txtAscent.Text
CrystalReport1.SectionLineHeight(sectionLineHeightN) = TempText
sectionLineHeightN = sectionLineHeightN + 1
End If
' Get font changes for section from form
If Len(Trim(SectionEdit!txtFontName.Text)) <> 0 And Val(SectionEdit!txtFontSize.Text) <> 0 Then
TempText = SectionEdit!cmbSectionType.Text & "." & SectionEdit!txtGroup.Text & "." & SectionEdit!txtSectionNumber.Text
TempText = TempText & ";" & SectionEdit!txtFontName.Text & ";" & SectionEdit!txtFontSize.Text
If SectionEdit!chkItalic.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
If SectionEdit!chkBold.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
If SectionEdit!chkUnderline.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
If SectionEdit!chkStrikethru.Value = 1 Then TempText = TempText & ";T" Else TempText = TempText & ";F"
CrystalReport1.SectionFont(sectionFontN) = TempText
sectionFontN = sectionFontN + 1
End If
Exit Do
Case "Cancel"
MsgBox "Cancel was pressed - no changes will be made to the section settings", vbOKOnly + vbCritical, "Cancel Pressed"
Exit Do
End Select
Loop
Unload SectionEdit
End Select
Loop
Unload Sections
' Offer opportunity to see what you did to the report
If MsgBox("Do you want to preview the report?", vbYesNo + vbQuestion, "Preview Report?") = vbYes Then
CrystalReport1.Destination = 0 ' Window
CrystalReport1.Action = 1 ' Print
ErrorTrap "FormatLinesSections"
hwndPreviewWindow = GetActiveWindow()
Do While IsWindow(hwndPreviewWindow)
DoEvents
Loop
End If
' Close the report
CrystalReport1.ReportFileName = ""
MsgBox "Lines/Sections Complete!", vbOKOnly, "Operation Completed"
End Sub
Seagate Software IMG Holdings, Inc. http://www.seagatesoftware.com Support services: http://support.seagatesoftware.com |